#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    timer=new QTimer;


    //pixmap显示速度快，image适合大图片
    QImage img;
    img.load("C:\\Users\\hyb\\Desktop\\qt-learning\\QTonline\\QTimer\\1.png");
    ui->label->setPixmap(QPixmap::fromImage(img));

    //定时器时间到，发出timeout信号
    connect(timer,&QTimer::timeout,this,&Widget::timeout_slot);

    connect(ui->oneButton,&QPushButton::clicked,[this]()
    {
        QTimer::singleShot(1000,this,SLOT(timeout_slot()));//单次定时
       // QMessageBox::information(this,"信息","点击浏览");
    });
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_startButton_clicked()
{
    timer->start(TIMEOUT);
}
void Widget::on_stopButton_clicked()
{
    timer->stop();
}

void Widget::timeout_slot()
{
    QString path="C:\\Users\\hyb\\Desktop\\qt-learning\\QTonline\\QTimer\\";
    path += QString::number(picId);
    path += ".png";

    QImage img;
    img.load(path);
    ui->label->setPixmap(QPixmap::fromImage(img));

    picId++;
    if(picId==3)picId=1;
}
